<?php
/* OpenBIBLIO -- A library administration web interface
 * Copyright (C) 2002-2005 Fr&eacute;d&eacute;ric Descamps <lefred@tiscali.be>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
 $sw		= $_POST['sw'];
 $el_nom	= $_POST['el_nom'];
 $el_prenom	= $_POST['el_prenom'];
 $el_classe_id  = $_POST['el_classe_id'];
                        if($sw==1)
                        {                       
                          $requete = "select * from eleves where nom ='$el_nom' and prenom ='$el_prenom' and del=0";
                          $resultat = biblio_db_query($requete);
                          $trouve=biblio_db_num_rows($resultat);
                          if ($trouve > 0)
                          {
                           echo "<CENTER><BR>";
			   echo _("L'&eacute;l&egrave;ve");
			   echo " <b>$el_prenom $el_nom</b> ";
			   echo _("est d&eacute;j&agrave; existant dans la base de donn&eacute;es, recommencez!");
			   echo "<BR><BR>";
                           echo "<A HREF=\"admin.php?action=add&type=eleve\">";
			   echo _("retour");
			   echo "</A></CENTER>";
                          }
                          else 
                          {
                           $requete = "select * from code_eleves";
                           $resultat = biblio_db_query($requete);
                           while ($row = biblio_db_fetch_array($resultat))
                           {
                             $code=$row['code'];
                           }
                           $code = sprintf("%06d",$code + 1);
                           $requete = "update code_eleves set code='$code'";
                           if(!($resultat = biblio_db_query($requete))) { 
							   echo "PROBLEME : " .biblio_db_error();
							   exit;   
						   }                           
                           $newdate = date("Y-m-d");
                           $requete = "insert into eleves (nom,prenom,classe_id,newdate,code) values ('$el_nom','$el_prenom','$el_classe_id','$newdate',$code)";
                           if(!($resultat = biblio_db_query($requete)))
                           { echo "PROBLEME CREATION : " .biblio_db_error(); exit;}    
                           put_log(2,$requete,$user);                       
                           echo "<CENTER><BR><b>$el_prenom $el_nom</b> ";
			   echo _("est ajout&eacute; le $newdate &agrave; la base de donn&eacute;es avec le code");
			   echo ": <b>$code</b>.<br>";
                           $eleve_id=mysql_insert_id();
			   if ($_FILES['el_photo']['tmp_name'])
			   {
				$filename = $eleve_id . ".jpg";
				$photo_path=get_picspath();
			        system("cp ". $_FILES['el_photo']['tmp_name'] ." $photo_path/$filename");
                                system("cd $photo_path; mogrify -geometry 150x100 $filename");
			   }
                           echo "<BR><A HREF=\"printeleve.php?eleve_id=$eleve_id\" target=\"NEW\">";
			   echo _("Imprimer la carte de cet utilisateur");
			   echo "</A>";
                           echo "<BR><A HREF=\"admin.php?action=add&type=eleve\">";
			   echo _("Ajouter un nouvel &eacute;l&egrave;ve");
			   echo "</A></center>";
                          }
                        }
                        else
                        {
                          ?>
                                <CENTER><H3>
				<?php echo _("Ajouter un &eacute;l&egrave;ve"); ?>
				</H3>
                                <FORM enctype="multipart/form-data" action="admin.php" METHOD="POST">
                                <TABLE BORDER=0>
                                <TR>
                                <TD>
				<?php echo _("Nom"); ?>
				:</TD><TD><INPUT TYPE="text" NAME="el_nom" size=15></TD>
                                <TR>
                                <TD>
				<?php echo _("Pr&eacute;nom"); ?> 
				:</TD><TD><INPUT TYPE="text" NAME="el_prenom" size=15></TD>
                                <TR>
                                <TD>
				<?php echo _("Classe"); ?>
				:</TD><TD><select NAME = "el_classe_id">
                                <?php
                                $requete = "SELECT * FROM classes order by classe"; 
				if(!($resultat = biblio_db_query($requete)))
				{ print "PROBLEME : " .biblio_db_error(); }
				else 
				{
					while ($row = biblio_db_fetch_array($resultat)) 
					{      
					        $el_classe_id = $row['id'];           
						$classe_l =  $row['classe'];                                
						print "<option VALUE=\"$el_classe_id\">$classe_l";
					}
				}                                
                                
                                ?>
                                </select>
                                </TD>
                                <TR>
                                <TD>
				<?php echo _("Photo"); ?>
				:</TD><TD><input type=file name="el_photo"></TD></TR>
                                </TABLE><BR>
                                <INPUT TYPE="hidden" NAME="user" value="<?php echo $user; ?>">
                                <INPUT TYPE="hidden" NAME="action" value="<?php echo $action; ?>">
                                <INPUT TYPE="hidden" NAME="type" value="<?php echo $type; ?>">
                                <INPUT TYPE="hidden" NAME="sw" value="1">
                                <input type="Submit" value="Enregistrer">
                                </FORM>
                                </CENTER>
                                <?php

                        }
?>              
<br><br>
<div>
<span id=left-text>
<A HREF="admin.php?menu=1">
<?php echo _("retour menu administration"); ?>
</A><BR>
<A HREF="index.php">
<?php echo _("retour menu principal"); ?>
</A></span>
</div>
<br>
